<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.User"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.Article"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
Article article = (Article) request.getAttribute("article");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String success = (String)request.getAttribute("success");
User user = (User) request.getAttribute("user_logged_in");
String url = (String) request.getAttribute("url");

//Set content for seo
String nameServer = UrlHelper.getDomainServer(request);
String title = "Submit an article - " + nameServer;
String description = "Free submit a new article on " + nameServer + " website system.";
String keywords = "submit article, free submit, free submit article, write article, send article, archives, archives article, submit article, article commit";
String urlSeo = UrlHelper.getServerUrl(request) + "/submit-article";
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=urlSeo %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

<script src="/sources/ckeditor/ckeditor.js"></script>
		
            <div id="mainContent" class="left">
                <div id="editArticlePage">
                	<h3 class="title">Submit an article</h3>
                	<div class="adv">
						<script type="text/javascript"><!--
						google_ad_client = "ca-pub-2883566427648799";
						/* link_menu 468x15 */
						google_ad_slot = "8735411486";
						google_ad_width = 468;
						google_ad_height = 15;
						//-->
						</script>
						<script type="text/javascript"
						src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
						</script>
	                </div>
                	<% if (success != null) { %>
                	<div class="messageBox-success"><%=success %></div>
                	<% } %>
					<form method="post" action="" class="formStyle">
						<% if (user == null) { %>
						<div class="left <%=check.get("name") != null ? "error" : ""%>">
                        	<label>Author Name (required)</label>
                            <input type="text" name="name" value="<%=article.getAuthorName() %>"/>
                            <% if (check.get("name") != null) { %>
                            <p class="errorMessage"><%=check.get("name") %></p>
                            <% } %>
                        </div>
                        <div class="right <%=check.get("email") != null ? "error" : ""%>">
                        	<label>Author Email (required)</label>
                            <input type="text" name="email" value="<%=article.getEmail() %>"/>
                            <% if (check.get("email") != null) { %>
                            <p class="errorMessage"><%=check.get("email") %></p>
                            <% } %>
                        </div>                                                
                        <div class="clearbreak"></div>
						<% } %>
						
                        <div class="left <%=check.get("title") != null ? "error" : ""%>">
                        	<label>Article Title (required)</label>
                            <input type="text" name="title" value="<%=article.getTitle() %>"/>
                            <% if (check.get("title") != null) { %>
                            <p class="errorMessage"><%=check.get("title") %></p>
                            <% } %>
                        </div>
                        <div class="right <%=check.get("category") != null ? "error" : ""%>">
                        	<label>Category (required)</label>
                            <select name="category">
                            	<% for (Category category : categories) { %>                                
                                <option value="<%=category.getId()%>" <%=category.getId().equalsIgnoreCase(article.getCategory()) ? "selected=\"selected\"" : "" %>><%=category.getName() %></option>
                                <% } %>
                            </select>
                            <% if (check.get("category") != null) { %>
                            <p class="errorMessage"><%=check.get("category") %></p>
                            <% } %>
                        </div>                                                
                        <div class="clearbreak"></div>
                        <div class="<%=check.get("content") != null ? "error" : ""%>">
                        	<label>Content (required)</label>
                            <textarea name="content" class="ckeditor"><%=article.getContent() %></textarea>
                            <% if (check.get("content") != null) { %>
                            <p class="errorMessage"><%=check.get("content") %></p>
                            <% } else { %>
                            <p class="note">Minimum 500 charracter</p>
                            <% } %>
                        </div>
                        <div class="keyword <%=check.get("keywords") != null ? "error" : ""%>">
                        	<label>Keyword</label>
                            <input type="text" name="keywords" value="<%=StringHelper.listToString(article.getKeywords(), ", ")%>"/>
                            <% if (check.get("keywords") != null) { %>
                            <p class="errorMessage"><%=check.get("keywords") %></p>
                            <% } else { %>
                            <p class="note">Example : keyword1, keyword2, ...</p>
                            <% } %>
                        </div>
                        <div class="clearbreak"></div>
                        
                        <% if (user == null) { %>
                        <div class="keyword <%=check.get("website") != null ? "error" : ""%>">
                        	<label>Author website</label>
                            <input type="text" name="website" value="<%=url != null ? url : article.getWebsite()%>"/>
                            <% if (check.get("website") != null) { %>
                            <p class="errorMessage"><%=check.get("website") %></p>
                            <% }%>
                        </div>
                        
                        <div class="keywords <%=check.get("captcha") != null ? "error" : ""%>">
                        	<label>Security Code (<a href="/login">login</a> to remove captcha)</label>
                        	<script>
					        	var RecaptchaOptions = { theme : 'red'};
					  		</script>
							<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
							
							<% if (check.get("captcha") != null) { %>
                            <p class="errorMessage"><%=check.get("captcha") %></p>
                            <% } %>
                        </div>
                        <% } %>
                        <div class="clearafter">
                        	<button type="submit">Save</button>
                        	<div class="right">
                        		<script type="text/javascript"><!--
								google_ad_client = "ca-pub-2883566427648799";
								/* question 468x60 */
								google_ad_slot = "8574497481";
								google_ad_width = 468;
								google_ad_height = 60;
								//-->
								</script>
								<script type="text/javascript"
								src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
								</script>
                        	</div>
                        </div>
                    </form>
                </div>
            </div>
            
            <jsp:include page="/elements/right.jsp" />
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />